package com.ruoyi.module.system.controller;


import com.ruoyi.core.entity.BaseMap;
import com.ruoyi.core.entity.Output;
import com.ruoyi.web.annotations.ApiController;
import com.ruoyi.web.annotations.ApiLog;
import com.ruoyi.web.domain.SysModColumn;
import com.ruoyi.web.service.SysModColumnService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

@ApiController
@ApiLog
@RestController
@RequestMapping("/sysModColumn")
public class SysModColumnController {


    @Autowired
    private SysModColumnService sysModColumnService;

    @PostMapping("/add")
    public Output<SysModColumn> add(@Valid @RequestBody SysModColumn entity) {

        return Output.success(sysModColumnService.add(entity));

    }

    @PostMapping("/edit")
    public Output<SysModColumn> edit(@Valid @RequestBody SysModColumn entity) {

        return Output.success(sysModColumnService.edit(entity));

    }

    @PostMapping("/delete")
    public Output<Object> delete(@Valid @RequestBody SysModColumn entity) {

        sysModColumnService.delete(entity.getColumnName());

        return Output.success();

    }

    @PostMapping("/getById")
    public Output<SysModColumn> getById(@Valid @RequestBody SysModColumn entity) {

        return Output.success(sysModColumnService.getById(entity));

    }

    @PostMapping("/getList")
    public Output<List<SysModColumn>> getList(@RequestBody BaseMap entity) {

        return Output.success(sysModColumnService.getList(entity.getString("mod_id")));

    }

//    private List<Creator.CreatorItem> getWhere() {
//        List<Creator.CreatorItem> where = new ArrayList<>();
//        Creator.CreatorItem item1 = new Creator.CreatorItem(ConnType.and, "modId", OperatorType.eq, null);
//        where.add(item1);
//        return where;
//    }
//
//    @PostMapping("/getList")
//    public Output<List<SysModColumn>> getList(@RequestBody BaseMap entity) {
//
//        if (entity == null) {
//            entity = new BaseMap();
//        }
//
//        QueryCreator queryCreator = new QueryCreator(entity);
//        queryCreator.setWhere(getWhere());   //动态构建查询条件（后端构建比较安全）
//
//        List<SysModColumn> list = sysModColumnService.list(queryCreator);
//
//        return Output.success(list);
//
//    }


}
